package com.coco.group.controller;

import com.coco.common.annotation.IngoreResponseAdvice;
import com.coco.common.result.ResultData;
import com.coco.group.pojo.TbGroupBuyRecord;
import com.coco.group.service.GroupBuyRecordService;
import com.coco.group.vo.GroupBuyRecordVo;

import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Package: com.coco.group.controller
 * @Author: 张dy
 * @Date: Created in 2021/7/29 下午 7:57
 * 团购纪录
 */
@RestController
@RequestMapping("/group/record")
public class GroupBuyRecordController {

    @Autowired
    private GroupBuyRecordService groupBuyRecordService;

    /**
     * 查询所有的拼团记录
     * @Author: 张dy
     * @Date: 2021/7/29
     */
    @GetMapping("/findAll")
    private List<TbGroupBuyRecord> findAll(){
        return groupBuyRecordService.findAll();
    }


    /**
     * 分页和模糊
     * @Author: 张dy
     * @Date: 2021/7/29
     */
    @PostMapping("/search")
    private ResultData<TbGroupBuyRecord> search(@RequestBody GroupBuyRecordVo groupBuyRecordVo){
        return groupBuyRecordService.search(groupBuyRecordVo);
    }

    @DeleteMapping("/deleteById/{id}")
    public void deleteById(@PathVariable("id") Integer id){
        groupBuyRecordService.deleteById(id);
    }

    /**
     * 添加拼团记录
     * @param record
     */
    @PostMapping("/addRecord")
    @IngoreResponseAdvice
    public TbGroupBuyRecord  addRecord(@RequestBody TbGroupBuyRecord record){
        groupBuyRecordService.addRecord(record);
        System.out.println(record.getId());
        return record;
    }

    /**
     * 根据订单查找拼团记录
     * @author HanSama
     * @date 2021/8/1 20:42
     * @param tradeNo
     * @return com.coco.group.pojo.TbGroupBuyRecord
     */
    @PostMapping("/findByOrderId/{tradeNo}")
    @IngoreResponseAdvice
    public TbGroupBuyRecord findByOrderId(@PathVariable("tradeNo") String tradeNo){
     return groupBuyRecordService.findByOrderId(tradeNo);
    }


    /**
     * 修改参与人数
     * @author HanSama
     * @date 2021/8/1 20:42
     * @param id
     */
    @PostMapping("/changeJoinNum/{id}")
    @IngoreResponseAdvice
    public void changeJoinNum(@PathVariable("id") Long id){
        groupBuyRecordService.changeJoinNum(id);
    }

    /**
     * 拼团完成
     * @author HanSama
     * @date 2021/8/1 20:42
     * @param id
     */
    @PostMapping("/changeStatusToSuccess/{id}")
    @IngoreResponseAdvice
    public void changeStatusToSuccess(Long id){
        groupBuyRecordService.changeStatusToSuccess(id);
    }

    /**
     * 根据邀请码查询单条
     * @param code
     * @return
     */
    @GetMapping("/findByOrderId/{code}")
    @IngoreResponseAdvice
    public TbGroupBuyRecord findByInvitationCode(@PathVariable("code") String code){
        return groupBuyRecordService.findByInvitationCode(code);
    }
}
